Add a header menu to settings demo
authorMatthias Clasen <mclasen@redhat.com>
Sun, 31 May 2020 18:44:42 +0000 (14:44 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 2 Jun 2020 02:10:53 +0000 (22:10 -0400)
Allow toggling column visibility from here.

demos/gtk-demo/listview_settings.c
demos/gtk-demo/listview_settings.ui

index c00024a68ed0b15a37bdb14a1d4022724497ecb2..24c42ea232781de605d28da7e548ce735c2d3e26 100644 (file)
@@ -300,7 +300,11 @@ do_listview_settings (GtkWidget *do_widget)
       GtkBuilderScope *scope;
       GtkBuilder *builder;
       GtkColumnViewColumn *name_column;
+      GtkColumnViewColumn *type_column;
+      GtkColumnViewColumn *default_column;
       GtkSorter *sorter;
+      GActionGroup *actions;
+      GAction *action;
 
       g_type_ensure (SETTINGS_TYPE_KEY);
 
@@ -320,6 +324,22 @@ do_listview_settings (GtkWidget *do_widget)
 
       listview = GTK_WIDGET (gtk_builder_get_object (builder, "listview"));
       columnview = GTK_WIDGET (gtk_builder_get_object (builder, "columnview"));
+      type_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "type_column"));
+      default_column = GTK_COLUMN_VIEW_COLUMN (gtk_builder_get_object (builder, "default_column"));
+
+      actions = G_ACTION_GROUP (g_simple_action_group_new ());
+
+      action = G_ACTION (g_property_action_new ("show-type", type_column, "visible"));
+      g_action_map_add_action (G_ACTION_MAP (actions), action);
+      g_object_unref (action);
+
+      action = G_ACTION (g_property_action_new ("show-default", default_column, "visible"));
+      g_action_map_add_action (G_ACTION_MAP (actions), action);
+      g_object_unref (action);
+
+      gtk_widget_insert_action_group (columnview, "columnview", actions);
+      g_object_unref (actions);
+
       model = create_settings_model (NULL, NULL);
       treemodel = gtk_tree_list_model_new (FALSE,
                                            model,
index cc9f7f8a9c9776b0bec8d88eb2194c7d7a2b5e29..96d2a22cfe6e23f24f674ce7d499d4dc24940cee 100644 (file)
@@ -77,6 +77,7 @@
                     <child>
                       <object class="GtkColumnViewColumn" id="name_column">
                         <property name="title">Name</property>
+                        <property name="header-menu">header_menu</property>
                         <property name="factory">
                           <object class="GtkBuilderListItemFactory">
                             <property name="bytes"><![CDATA[
                     <child>
                       <object class="GtkColumnViewColumn">
                         <property name="title">Value</property>
+                        <property name="header-menu">header_menu</property>
                         <property name="factory">
                           <object class="GtkBuilderListItemFactory">
                             <property name="bytes"><![CDATA[
                       </object>
                     </child>
                     <child>
-                      <object class="GtkColumnViewColumn">
+                      <object class="GtkColumnViewColumn" id="type_column">
                         <property name="title">Type</property>
+                        <property name="header-menu">header_menu</property>
                         <property name="factory">
                           <object class="GtkBuilderListItemFactory">
                             <property name="bytes"><![CDATA[
                       </object>
                     </child>
                     <child>
-                      <object class="GtkColumnViewColumn">
+                      <object class="GtkColumnViewColumn" id="default_column">
                         <property name="title">Default</property>
+                        <property name="header-menu">header_menu</property>
                         <property name="factory">
                           <object class="GtkBuilderListItemFactory">
                             <property name="bytes"><![CDATA[
       </object>
     </child>
   </object>
+  <menu id="header_menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Type</attribute>
+        <attribute name="action">columnview.show-type</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Default value</attribute>
+        <attribute name="action">columnview.show-default</attribute>
+      </item>
+    </section>
+  </menu>
 </interface>